home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / wildcat / wc30rec.zip / BTREEO.PAS < prev    next >
Pascal/Delphi Source File  |  1992-05-12  |  5KB  |  141 lines

  1.   procedure CreateMsgStatusRec;
  2.   var
  3.     RefNr : LongInt;
  4.     MsgHeader : MsgStatusType;
  5.     LockStatus : Boolean;
  6.  
  7.   begin
  8.     LockStatus := LockBTree(dbMsg);
  9.     with MsgHeader do
  10.       begin
  11.         Status := 0;
  12.         LowMsg := 0;
  13.         HighMsg := 0;
  14.         ActiveMsg := 0;
  15.         LastExtract := 0;
  16.         Len := 12;
  17.         Next := 0;
  18.       end;
  19.     BtAddRec(MsgFile, RefNr, MsgHeader);
  20.     if not IsamOk or (RefNr <> 1) then
  21.       LogFatalError('Unable to add message status record', IsamError);
  22.     if LockStatus then
  23.       UnLockBtree(dbMsg);
  24.   end;
  25.  
  26.  
  27.   procedure OpenMessageDatabase(MsgFilePath : IsamFileBlockName; Conf : Word);
  28.   var
  29.     IID : IsamIndDescr;
  30.  
  31.   begin
  32.     MsgFilePath := MsgFilePath+'MSG'+LeftPadCh(Long2Str(Conf), '0', 3);
  33.     if not ExistFile(MsgFilePath+'.DAT') then
  34.       begin
  35.         IID[MsgNumberKey].KeyL := 2;
  36.         IID[MsgNumberKey].AllowDupK := False;
  37.         IID[MsgOrigNumKey].KeyL := 21;
  38.         IID[MsgOrigNumKey].AllowDupK := False;
  39.         IID[MsgDestNumKey].KeyL := 21;
  40.         IID[MsgDestNumKey].AllowDupK := False;
  41.         IID[MsgSubjectKey].KeyL := 21;
  42.         IID[MsgSubjectKey].AllowDupK := False;
  43.         IID[MsgReceiveKey].KeyL := 21;
  44.         IID[MsgReceiveKey].AllowDupK := False;
  45.         IID[MsgDeleteKey].KeyL := 2;
  46.         IID[MsgDeleteKey].AllowDupK := False;
  47.         BtCreateFileBlock(MsgFilePath, 512, 6, IID);
  48.         if IsamOk then
  49.           begin
  50.             OpenBtreeFile(MsgFile, MsgFilePath);
  51.             CreateMsgStatusRec;
  52.           end
  53.         else
  54.           LogFatalError('Unable to create conference '+Long2Str(Conf)+' message database', IsamError);
  55.       end
  56.     else
  57.       OpenBtreeFile(MsgFile, MsgFilePath);
  58.     if not IsamOk then
  59.       LogFatalError('Error opening conference '+Long2Str(Conf)+' message database', IsamError);
  60.     OpenDatabase[dbMsg] := True;
  61.   end;
  62.  
  63.  
  64.   procedure OpenUserDatabase;
  65.   var
  66.     RecSize : LongInt;
  67.     IID : IsamIndDescr;
  68.     DataBasePath : IsamFileBlockName;
  69.  
  70.   begin
  71.     DataBasePath := Cfig.UserDataBasePath+'ALLUSERS';
  72.     if not ExistFile(DataBasePath+'.DAT') then
  73.       begin
  74.         IID[UserNameKey].KeyL := 19;
  75.         IID[UserNameKey].AllowDupK := False;
  76.         IID[UserSecKey].KeyL := 27;
  77.         IID[UserSecKey].AllowDupK := False;
  78.         IID[UserExpDateKey].KeyL := 2;
  79.         IID[UserExpDateKey].AllowDupK := True;
  80.         IID[UserAliasKey].KeyL := 19;
  81.         IID[UserAliasKey].AllowDupK := False;
  82.         BtCreateFileBlock(DataBasePath, UserRecSize + (Cfig.MaxConfAreas * SizeOf(ConfUserType)), 4, IID);
  83.         if not IsamOk then
  84.           LogFatalError('Unable to create user database', IsamError);
  85.       end;
  86.     OpenBtreeFile(UserFile, DataBasePath);
  87.     if not IsamOk then
  88.       LogFatalError('Unable to open user database', IsamError);
  89.     RecSize := BtDatRecordSize(UserFile);
  90.     if not IsamOk or (RecSize <> UserRecSize + (Cfig.MaxConfAreas * SizeOf(ConfUserType))) then
  91.       HaltWithError('User record size mismatch', '');
  92.     ReadMInfo(True);
  93.     MInfo.TotalUsers := BtreeUsedKeys(UserFile, UserNameKey);
  94.     WriteMInfo;
  95.     OpenDatabase[dbUser] := True;
  96.   end;
  97.  
  98.  
  99.   procedure OpenFileDatabase;
  100.   var
  101.     IID : IsamIndDescr;
  102.     DataBasePath : IsamFileBlockName;
  103.  
  104.   begin
  105.     DataBasePath := Cfig.FileDataBasePath+'ALLFILES';
  106.     if not ExistFile(DataBasePath+'.DAT') then
  107.       begin
  108.         IID[FileNameKey].KeyL := 9;
  109.         IID[FileNameKey].AllowDupK := False;
  110.         IID[FileAreaKey].KeyL := 11;
  111.         IID[FileAreaKey].AllowDupK := False;
  112.         IID[FileDateKey].KeyL := 8;
  113.         IID[FileDateKey].AllowDupK := True;
  114.         IID[FilePWKey].KeyL := 10;
  115.         IID[FilePWKey].AllowDupK := False;
  116.         IID[FileUpKey].KeyL := 19;
  117.         IID[FileUpKey].AllowDupK := True;
  118.         IID[FileKWKey].KeyL := 8;
  119.         IID[FileKWKey].AllowDupK := True;
  120.         BtCreateFileBlock(DataBasePath, 297, 6, IID);
  121.         if not IsamOk then
  122.           LogFatalError('Unable to create file database', IsamError);
  123.       end;
  124.     OpenBtreeFile(FileSpec, DataBasePath);
  125.     if not IsamOk then
  126.       LogFatalError('Unable to open file database', IsamError);
  127.     ReadMInfo(True);
  128.     MInfo.TotalFiles := BtreeUsedKeys(FileSpec, FileNameKey);
  129.     WriteMInfo;
  130.     OpenDatabase[dbFile] := True;
  131.   end;
  132.  
  133.  
  134.   procedure OpenAllDatabases;
  135.   begin
  136.     if not OpenDatabase[dbUser] then
  137.       OpenUserDatabase;
  138.     if not OpenDatabase[dbFile] then
  139.       OpenFileDatabase;
  140.   end;
  141.